package cn.b.training.baby_education_training.service.impl;

import cn.b.training.baby_education_training.entity.*;
import cn.b.training.baby_education_training.repository.AgeTagRepository;
import cn.b.training.baby_education_training.repository.VaccineRepository;
import cn.b.training.baby_education_training.service.VaccineService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

/**
 * @program: baby_education_training
 * @description
 * @author: wuying
 * @create: 2022-12-04 17:24
 **/
@Service
public class VaccineServiceImpl implements VaccineService {
    @Autowired
    private AgeTagRepository ageTagRepository;
    @Autowired
    private VaccineRepository vaccineRepository;
    @Override
    public boolean addVaccine(Vaccine vaccine) {
            vaccine.setAgeTag(vaccine.getAgeTag());
            vaccine.setVaccineName(vaccine.getVaccineName());
            vaccine.setVaccineNum(vaccine.getVaccineNum());
            vaccine.setVaccineEffect(vaccine.getVaccineEffect());
            vaccine.setVaccineReact(vaccine.getVaccineReact());
            vaccine.setVaccineResult(vaccine.getVaccineResult());
            vaccine = vaccineRepository.save(vaccine);
        if (vaccine!=null){
            return true;
        }
        return false;
    }

    @Override
    public Page<Vaccine> getAllVaccine(Integer page, Integer size) {
        return vaccineRepository.findAll(PageRequest.of(page,size));
    }

    @Override
    public Boolean deleteVaccineById(Long id) {
        try{
            this.vaccineRepository.deleteById(id);
            return true;
        }catch (Exception e){
            e.printStackTrace();
            return false;
        }
    }
}
